<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>第35组的 OJ 平台</title>
        <meta name="description" content="Charcoal is a free Bootstrap 4 UI kit build by @attacomsian at Wired Dots." />
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <!--Bootstrap 4-->
        <link rel="stylesheet" href="css/bootstrap.min.css">
    </head>
    <body>

        <nav class="navbar navbar-expand-md navbar-dark fixed-top sticky-navigation">
            <a class="navbar-brand font-weight-bold" href="#">我的 OJ 系统</a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#topMenu" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <a href="logout">注销</a>
            <div class="collapse navbar-collapse" id="topMenu">
                <ul class="navbar-nav ml-auto">
                </ul>
            </div>
        </nav>

        <!--hero section-->
        <section class="bg-hero">
            <div class="container">
                <div class="row vh-100">
                    <div class="col-sm-12 my-auto text-center">
                        <h1>第35组的 OJ 平台</h1>
                        <p class="lead text-capitalize my-4">
                            基于 Java Servlet 实现的 OJ 系统.
                        </p>
                        <a href="https://gitee.com" class="btn btn-outline-light btn-radius btn-lg">项目链接</a>
                    </div>
                </div>
            </div>
        </section>

        <!--components-->
        <section class="my-5 pt-5">
            <div class="container">
                <div class="row mt-4">
                    <div class="col-sm-12 pb-4">
                        <div class="form-group">
                            <label for="title">标题</label>
                                <textarea class="form-control" id="title" style="width: 100%; height: 40px;"></textarea>
                        </div>
                    </div>
                </div>
                <div class="row mt-4">
                    <div class="col-sm-12 pb-4">
                        <div class="form-group">
                            <label for="level">难度</label>
                                <textarea class="form-control" id="level" style="width: 100%; height: 40px;"></textarea>
                        </div>
                    </div>
                </div>
                <div class="row mt-4">
                    <div class="col-sm-12 pb-4">
                        <div class="form-group">
                            <label for="description">题目描述</label>
                                <textarea class="form-control" id="description" style="width: 100%; height: 400px;"></textarea>
                        </div>
                    </div>
                </div>
                <div class="row mt-4">
                    <div class="col-sm-12 pb-4">
                        <div class="form-group">
                            <label for="TestCode">测试用例</label>
                                <textarea class="form-control" id="TestCode" style="width: 100%; height: 400px;"></textarea>
                        </div>
                    </div>
                </div>
                <div class="row mt-4">
                    <div class="col-sm-12 pb-4">
                        <div class="form-group">
                            <label for="codeEditor">代码</label>
                                <textarea class="form-control" id="codeEditor" style="width: 100%; height: 400px;"></textarea>
                        </div>
                    </div>
                </div>
                <button type="button" class="btn btn-primary" id="submitButton">提交</button>
            </div>
        </section>

        <!--footer-->
        <section class="py-5 bg-dark">
            <div class="container">
                <div class="row">
                    <div class="col-md-6 offset-md-3 col-sm-8 offset-sm-2 col-xs-12 text-center">
                        
                        <p class="pt-2 text-muted">
                            &copy; by 第35组
                        </p>
                    </div>
                </div>
            </div>
        </section>
        <script src="js/jquery.min.js"></script>
        <!-- 引入 ace.js -->
        <!-- <script src="https://cdn.bootcdn.net/ajax/libs/ace/1.2.9/ace.js"></script>
        <script src="https://cdn.bootcdn.net/ajax/libs/ace/1.2.9/ext-language_tools.js"></script> -->
        <script>
            function getUser(){
                $.ajax({
                    url:"admin",
                    type:"GET",
					success:function(data,status){
						if(!data.isAdmin){
							location.assign("index.html");
						}
					},
                    error:function(data,status){
                        location.assign("login.html");
                    }
                })
            }
            let button=document.querySelector("#submitButton");
            button.onclick=function(){
                let body={
                    id: 0,
                    title: title.value,
                    level: level.value,
                    description: description.value,
                    testCode: TestCode.value,
                    templateCode: codeEditor.value,
                };
                $.ajax({
                    url:"addProblem",
                    type:"POST",
                    data: JSON.stringify(body),
                    success:function(data,status){
                        if(data.correct){
                            location.assign("function.html");
                        }
                    }
                })
            }
            getUser();
        </script>
    </body>
</html>
